﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using TTTTBHYT.DAO;
using TTTTBHYT.VO;

namespace TTTTBHYT.BUS
{
    class Mau29BUS
    {
        private Mau29DAO mau29DAO;
        public Mau29BUS()
        {
            mau29DAO = new Mau29DAO();
        }
        private void GetMau29FromBHXH(MAU29VO Mau29VO, DataRow dr)
        {
            Mau29VO.SoKCB = dr["SoKCB"].ToString();
            Mau29VO.HoTen = Converter.TCVN3ToUnicode(dr["HO"].ToString().Trim() + " " + dr["Ten"].ToString());
            Mau29VO.NgaySinh = dr["NGAYSINH"].ToString();
            Mau29VO.GioiTinh = Convert.ToInt32(dr["GioiTinh"]);
            Mau29VO.DiaChi = Converter.TCVN3ToUnicode(Convert.ToString(dr["DiaChi"]));
            Mau29VO.MaDT = dr["MaDT"].ToString();
            Mau29VO.MaBV = dr["Ma_tinh"].ToString() + dr["Ma_BV"].ToString();
            Mau29VO.TenBV = Converter.TCVN3ToUnicode(dr["Ten_BV"].ToString());
            Mau29VO.MaTinh = Convert.ToString(dr["Ma_Tinh"]);
            Mau29VO.TuNgay = Convert.ToString(dr["TuNgay"]);
            Mau29VO.DenNgay = Convert.ToString(dr["DenNgay"]);
        }
        private void GetMau29(MAU29VO Mau29VO, DataRow dr)
        {
            Mau29VO.KeySL = dr["KEYSL"].ToString();
            Mau29VO.SoKCB = dr["SoKCB"].ToString();
            Mau29VO.HoTen = dr["HOTEN"].ToString();
            Mau29VO.NgaySinh = dr["NGAYSINH"].ToString();
            Mau29VO.GioiTinh = Convert.ToInt32(dr["GioiTinh"]);
            Mau29VO.DiaChi = Convert.ToString(dr["DiaChi"]);
            Mau29VO.MaDT = dr["MaDT"].ToString();
            Mau29VO.MaBV = dr["Ma_BV"].ToString();
            Mau29VO.TenBV = dr["Ten_BV"].ToString();
            Mau29VO.MaTinh = Convert.ToString(dr["Ma_Tinh"]);
            Mau29VO.TuNgay = Convert.ToString(dr["TuNgay"]);
            Mau29VO.DenNgay = Convert.ToString(dr["DenNgay"]);
            Mau29VO.MaBVDT = Convert.ToString(dr["Ma_BV_DT"]);
            Mau29VO.MaTinhDT = Convert.ToString(dr["Ma_Tinh_DT"]);
            Mau29VO.TenBVDT = dr["Ten_BV_DT"].ToString();
            Mau29VO.TuNgayDT = Convert.ToString(dr["TuNgayDT"]);
            Mau29VO.DenNgayDT = Convert.ToString(dr["DenNgayDT"]);
            Mau29VO.SoNgay = Convert.ToInt32(dr["SoNgay"]);
            Mau29VO.SoNgayTT = Convert.ToInt32(dr["SoNgayTT"]);
            Mau29VO.LoaiDT = Convert.ToInt32(dr["LoaiDT"]);
            Mau29VO.HangBV = Convert.ToInt32(dr["HangBV"]);
            Mau29VO.MaICD = Convert.ToString(dr["MaICD"]);
            Mau29VO.ChuanDoan = Convert.ToString(dr["ChuanDoan"]);
            Mau29VO.TTNV = Convert.ToInt32(dr["TTNV"]);
            Mau29VO.LoaiGT = Convert.ToInt32(dr["LoaiGT"]);
            Mau29VO.TheBHYT = Convert.ToInt32(dr["TheBHYT"]);
            Mau29VO.TuyenKham = Convert.ToInt32(dr["TuyenKham"]);
            Mau29VO.KetLuan = Convert.ToInt32(dr["KetLuan"]);
            Mau29VO.ThanhToan = Convert.ToInt32(dr["ThanhToan"]);
            Mau29VO.Quy = Convert.ToString(dr["Quy"]);
            Mau29VO.NgayCT = Convert.ToString(dr["Ngayct"]);
            Mau29VO.NgayTT = Convert.ToString(dr["NgayTT"]);
            Mau29VO.SoChungTu = Convert.ToInt32(dr["Sochungtu"]);
            Mau29VO.XetNghiem = Convert.ToInt32(dr["XetNghiem"]);
            Mau29VO.Ha = Convert.ToInt32(dr["Ha"]);
            Mau29VO.Thuoc = Convert.ToInt32(dr["Thuoc"]);
            Mau29VO.Mau = Convert.ToInt32(dr["Mau"]);
            Mau29VO.Thuthuat = Convert.ToInt32(dr["Thuthuat"]);
            Mau29VO.VatTu = Convert.ToInt32(dr["VatTu"]);
            Mau29VO.TienKham = Convert.ToInt32(dr["TienKham"]);
            Mau29VO.PhauThuatCao = Convert.ToInt32(dr["PhauThuatCao"]);
            Mau29VO.VatTuCao = Convert.ToInt32(dr["VatTuCao"]);
            Mau29VO.LamSangCao = Convert.ToInt32(dr["LamSangCao"]);
            Mau29VO.ThuocK = Convert.ToInt32(dr["ThuocK"]);

            Mau29VO.XetNghiemKCB = Convert.ToInt32(dr["XetNghiemKCB"]);
            Mau29VO.HaKCB = Convert.ToInt32(dr["HaKCB"]);
            Mau29VO.ThuocKCB = Convert.ToInt32(dr["ThuocKCB"]);
            Mau29VO.MauKCB = Convert.ToInt32(dr["MauKCB"]);
            Mau29VO.ThuthuatKCB = Convert.ToInt32(dr["ThuthuatKCB"]);
            Mau29VO.VatTuKCB = Convert.ToInt32(dr["VatTuKCB"]);
            Mau29VO.TienKhamKCB = Convert.ToInt32(dr["TienKhamKCB"]);
            Mau29VO.PhauThuatCaoKCB = Convert.ToInt32(dr["PhauThuatCaoKCB"]);
            Mau29VO.VatTuCaoKCB = Convert.ToInt32(dr["VatTuCaoKCB"]);
            Mau29VO.LamSangCaoKCB = Convert.ToInt32(dr["LamSangCaoKCB"]);
            Mau29VO.ThuocKKCB = Convert.ToInt32(dr["ThuocKKCB"]);

            Mau29VO.XetNghiemLyDo = Convert.ToString(dr["XetNghiemLyDo"]);
            Mau29VO.HaLyDo = Convert.ToString(dr["HaLyDo"]);
            Mau29VO.ThuocLyDo = Convert.ToString(dr["ThuocLyDo"]);
            Mau29VO.MauLyDo = Convert.ToString(dr["MauLyDo"]);
            Mau29VO.ThuthuatLyDo = Convert.ToString(dr["ThuthuatLyDo"]);
            Mau29VO.VatTuLyDo = Convert.ToString(dr["VatTuLyDo"]);
            Mau29VO.TienKhamLyDo = Convert.ToString(dr["TienKhamLyDo"]);
            Mau29VO.PhauThuatCaoLyDo = Convert.ToString(dr["PhauThuatCaoLyDo"]);
            Mau29VO.VatTuCaoLyDo = Convert.ToString(dr["VatTuCaoLyDo"]);
            Mau29VO.LamSangCaoLyDo = Convert.ToString(dr["LamSangCaoLyDo"]);
            Mau29VO.ThuocKLyDo = Convert.ToString(dr["ThuocKLyDo"]);

            Mau29VO.TienThanhToan = Convert.ToInt32(dr["TienThanhToan"]);
            Mau29VO.NbThanhToan = Convert.ToInt32(dr["NbThanhToan"]);
            Mau29VO.BhxhThanhToan = Convert.ToInt32(dr["BhxhThanhToan"]);
            if (dr["BhxhNDX"] != DBNull.Value) { Mau29VO.BhxhNDX = Convert.ToInt32(dr["BhxhNDX"]); };
            Mau29VO.Khac = Convert.ToInt32(dr["Khac"]);
            Mau29VO.KhacKCB = Convert.ToInt32(dr["KhacKCB"]);
            Mau29VO.KhacLyDo = Convert.ToString(dr["KhacLyDo"]);
        }
        public string GetTenBV(string maBV)
        {
            string TenBV="";
            MAU29VO Mau29VO = new MAU29VO();
            DataTable dataTable = new DataTable();
            dataTable = mau29DAO.SearchTenBV(maBV);
            foreach (DataRow dr in dataTable.Rows)
            {
                TenBV = Converter.TCVN3ToUnicode(dr["TEN_BV"].ToString().Trim());
            }
            return TenBV;
        }
        public MAU29VO GetMau29BySoKCB(string SoKCB)
        {
            MAU29VO Mau29VO = new MAU29VO();
            DataTable dataTable = new DataTable();
            dataTable = mau29DAO.SearchBySoKCB(SoKCB);
            foreach (DataRow dr in dataTable.Rows)
            {
                GetMau29(Mau29VO, dr);
            }
            return Mau29VO;
        }
        public MAU29VO GetMau29BySoKCBFromBHXH(string SoKCB)
        {
            MAU29VO Mau29VO = new MAU29VO();
            DataTable dataTable = new DataTable();
            dataTable = mau29DAO.SearchBySoKCBFromBHXH(SoKCB);
            if (dataTable != null)
            {
                foreach (DataRow dr in dataTable.Rows)
                {
                    GetMau29FromBHXH(Mau29VO, dr);
                }
            }
            return Mau29VO;
        }
        public MAU29VO InsertRecord(MAU29VO Mau29VO)
        {

            return mau29DAO.InsertRecord(Mau29VO); 
        }
        public bool UpdateRecord(MAU29VO Mau29VO)
        {
            return mau29DAO.UpdateRecord(Mau29VO);
        }
        public bool DeleteRecord(string SoKCB)
        {
            return mau29DAO.DeleteRecord(SoKCB);
        }
        public List<MAU29VO> GetListMau29()
        {
            List<MAU29VO> lstMau29 = new List<MAU29VO>();
            MAU29VO Mau29VO;
            DataTable dataTable = new DataTable();
            dataTable = mau29DAO.SearchAll();
            foreach (DataRow dr in dataTable.Rows)
            {
                Mau29VO = new MAU29VO();
                GetMau29(Mau29VO, dr);
                lstMau29.Add(Mau29VO);

            }
            return lstMau29;
        }
        public List<MAU29VO> GetListMau29(string Condition)
        {
            List<MAU29VO> lstMau29 = new List<MAU29VO>();
            MAU29VO Mau29VO;
            DataTable dataTable = new DataTable();
            dataTable = mau29DAO.Search(Condition);
            foreach (DataRow dr in dataTable.Rows)
            {
                Mau29VO = new MAU29VO();
                GetMau29(Mau29VO, dr);
                lstMau29.Add(Mau29VO);

            }
            return lstMau29;
        }
        public DataTable GetListBV(string Condition)
        {
           
            DataTable dataTable = new DataTable();
            dataTable = mau29DAO.SearchBV(Condition);
            return dataTable;
        }

    }
}
